package com.lanou.dllo.soccernews.detailActivty;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.fragment.homelinefragment.HeadlineFragment;

public class DetailRecommendPageActivity extends AppCompatActivity {
    private ImageView deImg;
    private WebView recommendWebView;
    private Long id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_recommend_page);
        recommendWebView = (WebView) findViewById(R.id.recommendweb);
        deImg = (ImageView) findViewById(R.id.deback);
        WebSettings webSettings = recommendWebView.getSettings();
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        //设置可以访问文件
        webSettings.setAllowFileAccess(true);
        //设置支持缩放
        webSettings.setBuiltInZoomControls(true);
        //设置 缓存模式
        recommendWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
// 开启 DOM storage API 功能
       // recommendWebView.getSettings().setDomStorageEnabled(true);
        Intent intent = getIntent();
        id = intent.getLongExtra("id", 0);
        String url = "https://api.dongqiudi.com/article/" + id + ".html";
        recommendWebView.loadUrl(url);


        recommendWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO Auto-generated method stub
                super.onProgressChanged(view, newProgress);
                Log.i("lanou", "当前网页加载进度:" + newProgress);
            }
        });
        //监听接收到错误信息的回调
        recommendWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // TODO Auto-generated method stub
                super.onReceivedError(view, errorCode, description, failingUrl);
                Log.i("lanou", errorCode + " " + description);
            }
        });

        deImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              finish();
            }
        });
    }
}
